package com.yyz.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyz.lease.common.exception.LeaseException;
import com.yyz.lease.common.result.ResultCodeEnum;
import com.yyz.lease.model.entity.SystemPost;
import com.yyz.lease.web.admin.mapper.SystemPostMapper;
import com.yyz.lease.web.admin.service.SystemPostService;
import org.springframework.stereotype.Service;

/**
 * @description 针对表【system_post(岗位信息表)】的数据库操作Service实现
 */
@Service
public class SystemPostServiceImpl extends ServiceImpl<SystemPostMapper, SystemPost>
        implements SystemPostService {

    @Override
    public void saveOrUpdateSystemPost(SystemPost systemPost) {
        boolean isUpdate = systemPost.getId() != null;
        if (isUpdate) {
            String name = getById(systemPost.getId()).getName();
            if (name.equals(systemPost.getName())) {
                saveOrUpdate(systemPost);
                return;
            }
        }
        LambdaQueryWrapper<SystemPost> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SystemPost::getName, systemPost.getName());
        long count = count(queryWrapper);
        if (!(count == 0)) {
            throw new LeaseException(ResultCodeEnum.ADMIN_POST_EXIST_ERROR);
        }
        saveOrUpdate(systemPost);
    }
}




